<?php

require_once(PATH_CLASS.'widget.class.php');
require_once(PATH_CLASS.'match.class.php');

class ranking extends widget{
  
  const CLASS_NAME = 'ranking';

  public function getDefaults() {
    $ret = parent::getDefaults();
    $ret = array_merge(array(
       'id'         => null
      ,'pars'       => array()
      ,'complet'    => true
      ,'classement' => true
      ,'matchs'     => array()
      ,'saison_id'  => saison::getCurrentId()
      ,'type'       => saison::CHAMPIONNAT
        
    ),$ret);
    
    return $ret;
  }

  public function __construct($params) {
    parent::__construct($params);
  }
  
  protected function _get_called_class() { return self::CLASS_NAME;  }

  public function _render() {
    $pars = $this->params;
    
    $ranking = match::getRanking($pars['saison_id'], $pars['type']);
    
    $params = array(
         'ranking'    =>  $ranking
        ,'display'    =>  array(
             'complet'    =>  (isset($pars['complet'])     ? $pars['complet']    : false)
            ,'classement' =>  (isset($pars['classement'])  ? $pars['classement'] : true)
            ,'matchs'     =>  (isset($pars['matchs'])      ? $pars['matchs']     : false)
            ,'demies'     =>  (isset($pars['demies'])      ? $pars['demies']     : true)
        )
    );
    
    $params = array_merge($params,$pars);
    
//    var_dump($params);
    
    $layout = $this->renderTplFromFile(__FILE__, $params);
    
    return $layout;
  }
}

